import java.util.Arrays;
import java.util.Random;

/**
 * @Author liangzai
 * @Description:
 */
public class Test {
    public static void orderArray(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            arr[i] = i;
        }
    }

    public static void norOrderArray(int[] arr){
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(10_0000);
        }
    }

    public static void testOther(){
        int[] array = new int[100000];
        norOrderArray(array);
        testShell(array);
        testHeap(array);
        testQuick(array);
        testMerge(array);
        //testBubble(array);
    }

    public static void testInsert(int[] arr){
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入时间："+ (endTime-startTime));
    }

    public static void testShell(int[] arr){
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序时间："+ (endTime-startTime));
    }

    public static void testSelect(int[] arr){
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序时间："+ (endTime-startTime));
    }

    public static void testHeap(int[] arr){
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序时间："+ (endTime-startTime));
    }

    public static void testBubble(int[] arr){
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.bubbleSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序时间："+ (endTime-startTime));
    }

    public static void testQuick(int[] arr){
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序时间："+ (endTime-startTime));
    }

    public static void testMerge(int[] arr){
        arr = Arrays.copyOf(arr,arr.length);
        long startTime = System.currentTimeMillis();
        Sort.mergeSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序时间："+ (endTime-startTime));
    }

    public static void testSimple() {
        int[] arr = {12,28,10,4,1,8,91,67,41,101,36,53,88,60};
        System.out.println(Arrays.toString(arr));
        Sort.mergeNorSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void main(String[] args) {
        //testSimple();
        testOther();
    }
}
